package cn.factorybox.item.controller;

import cn.factorybox.common.entity.Result;
import cn.factorybox.item.annotation.ControllerLogAnnotation;
import cn.factorybox.item.service.SystemUpdateLogService;
import cn.factorybox.model.entity.SystemUpdateLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author flypig
 * @version 1.0
 * @date 2020-11-24 13:55
 */

@Api(tags = "系统功能更新日志")
@RestController
@RequestMapping("system")
public class SystemUpdateLogController {

    @Autowired
    private SystemUpdateLogService systemUpdateLogService;

    @ControllerLogAnnotation(moduleName = "系统功能更新日志", functionName = "提交更新日志")
    @ApiOperation(value = "提交更新日志",notes = "提交更新日志")
    @PostMapping("/updatelog")
    public Result saveSystemUpdateLog(@RequestBody SystemUpdateLog systemUpdateLog) {
        systemUpdateLogService.save(systemUpdateLog);
        return Result.ok("提交更新日志成功");
    }

    @ControllerLogAnnotation(moduleName = "系统功能更新日志", functionName = "获取前8条更新日志")
    @ApiOperation(value = "获取前8条更新日志",notes = "获取前8条更新日志")
    @GetMapping("/updatelog")
    public Result selectList() {
        List<SystemUpdateLog> systemUpdateLogs = systemUpdateLogService.selectList();
        return new Result(systemUpdateLogs,"数据获取成功");
    }

    @ControllerLogAnnotation(moduleName = "系统功能更新日志", functionName = "删除日志")
    @ApiOperation(value = "删除日志",notes = "删除日志")
    @DeleteMapping("/updatelog")
    public Result deleteLog(@RequestParam("id") String id) {
        systemUpdateLogService.delete(id);
        return Result.ok("删除日志成功");
    }

}
